package com.wcity.manage.dao.mapper;

import com.wcity.manage.dao.dal.BaseMapper;
import com.wcity.manage.dao.model.Act;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.List;

/**
 * 后台权限dao接口
 *
 * @author dy
 */
@Repository
public interface ActMapper extends BaseMapper<Act, Serializable> {

    /**
     * 按actName查询
     *
     * @param actName
     * @return
     */
    @Select( " SELECT * FROM td_manage_act WHERE `action` = #{actName} LIMIT 1 " )
    Act findByActName(@Param("actName") String actName);

    /**
     * 根据权限识别id获取在导航栏显示的Act
     *
     * @param authIds
     * @return
     */
    List<Act> findNavByAuthIds(List<Integer> authIds);

    /**
     * 查询功能模块对应Act(`is_nav`=1且`parent_id`=0), 并级联查询其子权限
     *
     * @return
     */
    List<Act> findNavColChildren();

    /**
     * 查询子权限
     *
     * @param parentId
     * @return
     */
    List<Act> findChildren(@Param("parentId") int parentId);

    /**
     * 按authId查询数量
     *
     * @param authId
     * @return
     */
    @Select( " SELECT COUNT(1) FROM td_manage_act WHERE `auth_id` = #{authId} " )
    int countByAuthId(@Param("authId") int authId);

    /**
     * 按action查询数量
     *
     * @param action
     * @return
     */
    @Select( " SELECT COUNT(1) FROM td_manage_act WHERE `action` = #{action} " )
    int countByAction(@Param("action") String action);

}
